package cn.xy.ymcc.exception;

import cn.xy.ymcc.constants.GlobalError;
import cn.xy.ymcc.result.JSONResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(value = Exception.class)
    public JSONResult exceptionHandler(Exception e){
        e.printStackTrace();
        return JSONResult.error(GlobalError.ERROR_EXCEPTION.getMessage(),GlobalError.ERROR_EXCEPTION.getCode());
    }

    @ExceptionHandler(value = GlobalException.class)
    public JSONResult globalExceptionHandler(GlobalException e){
        e.printStackTrace();
        return JSONResult.error(e.getMessage(),e.getCode());
    }
}
